//
//  GuideView.m
//  LazyCat
//
//  Created by zhanshu on 15/9/16.
//  Copyright (c) 2015年 zhanshu. All rights reserved.
//

#import "GuideView.h"

@implementation GuideView

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
    }
    return self;
}
- (void)theGuideImg:(NSArray *)imgArr {
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    _scrollView.contentSize = CGSizeMake(ScreenWidth*imgArr.count, ScreenHeight);
    _scrollView.showsVerticalScrollIndicator = NO;
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.pagingEnabled = YES;
    _scrollView.delegate = self;
    [self addSubview:_scrollView];
    
    for (int i = 0; i < imgArr.count; i ++) {
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth*i, 0, ScreenWidth, ScreenHeight)];
        imgView.image = [UIImage getImgByName:imgArr[i]];
        [_scrollView addSubview:imgView];
        
        if (i == imgArr.count-1) {
            _endbtn = [UIButton buttonWithType:UIButtonTypeCustom];
            _endbtn.frame = CGRectMake(ScreenWidth*i+(ScreenWidth - 190)/2, ScreenHeight - 100, 190, 45);
            [_endbtn setImage:[UIImage imageNamed:@"体验.png"] forState:UIControlStateNormal];
            [_scrollView addSubview:_endbtn];
        }
    }
    _pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, ScreenHeight-40, ScreenWidth,10)];
    _pageControl.numberOfPages = imgArr.count;
    _pageControl.currentPage = 0;
    [self addSubview:_pageControl];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    CGFloat index = _scrollView.contentOffset.x/ScreenWidth;
    _pageControl.currentPage = index;
}
@end
